using System.Globalization;

namespace CSharpPro._1023;

public class Demo
{
    public void TestPrint()
    {
        int[] arr1 = new int[5];
        arr1[0] = 1;
        arr1[4] = 5;
        for (int i = 0; i < arr1.Length; i++)
        {
            Console.WriteLine(arr1[i]);
        }

        string[] arr2 = new string[5];
        arr2[0] = "hello";
        arr2[4] = "world";
        for (int i = 0; i < arr2.Length; i++)
        {
            Console.WriteLine(arr2[i]);
        }

        int[] arr3 = { 10, 9, 8, 7, 6, 5 };
        
        
        // 二维数组
        int[,] arr5 = new int [3, 3];
        arr5[0, 0] = 1;   
        arr5[1, 1] = 2;
        arr5[2, 2] = 3;
        int[,] arr6 =
        {
            { 1, 2, 3, 4 },
            {5, 6, 7, 8},
            {9, 10, 11, 12 }
        };
        Console.WriteLine();
        foreach (int i in arr3)
        {
            Console.Write(i+"\t");
        }
         Console.WriteLine();
    }
//冒泡
    public void TestPrint1()
    {
        int[] arr = { 1, 3, 5, 2, 4 };
        for(int i = 0;i<arr.Length -1;i++)
        {
            for (int j = 0; j < arr.Length - 1 - i; j++)
            {
                if (arr[j] > arr[j + 1])
                {
                    int temp = arr[j + 1];
                    arr[j+1] =  arr[j];
                    arr[j] = temp;
                }
            }
        }
        foreach (int i in arr)
        {
            Console.Write(i+"\t");
        }
    }
}